package com.example.back.mapper.otd;

import com.example.back.entity.otd.Videos;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.ArrayList;

@Mapper
public interface VideoMapper {
    @Select("SELECT v.id, v.face, v.url, v.length, v.title, v.userId, v.drb , v.viewnum , u.tx, u.yhm FROM video v, user u WHERE v.userId = u.id")
    ArrayList<Videos> getVideos();

    @Insert("INSERT INTO video(userId, face, url, length, title,  drb , viewnum) VALUES(#{userId}, #{face}, #{url}, #{length}, #{title}, #{drb} , 0)")
    int insertVideo(Videos videos);

    @Select("SELECT v.id , v.face, v.url, v.length, v.title, v.userId, v.drb , v.viewnum , u.tx, u.yhm FROM video v, user u , relations re WHERE v.userId = u.id AND re.userId = v.userId and re.fanId = #{param1} ")
    ArrayList<Videos> queryVideoByUserId(String userId);

    @Select("SELECT v.id, v.face, v.url, v.length, v.title, v.userId, v.drb , v.viewnum , u.tx, u.yhm FROM video v, user u WHERE v.userId = u.id ORDER BY v.viewnum DESC")
    ArrayList<Videos> queryVideoByviewnum();

    @Update("UPDATE video SET viewnum = viewnum+1 WHERE id = #{param1} ")
    int updateVideoviewnum(String id);
}
